<template>
	<div class="pylst_list">
		<h3 class="u-smtitle">歌曲列表</h3>
		<ol class="u-songs">
			<li class="u-song" v-for="(item,index) in list" @click="handleClick(index)">
				<div class="sgi_fl">{{index+1}}</div>
				<div class="sgi_fr f-bd f-bd-btm">
					<div class="sgich_fl">
						<div class="f-thide sgich_tl">
							{{item.name}}
						</div>
						<div class="f-thide sgich_info" data-reactid="62" >
							<span v-for="(nm,index) in item.ar">
								{{nm.name}} 
								<span v-if="index == index && item.ar.length >= index+2">/</span>
							</span>
							-
							{{item.al.name}}
						</div>
					</div>
					<div class="sgich_fr" data-reactid="65">
						<span class="u-hmsprt sgich_ply" data-reactid="66"></span>
					</div>
				</div>
			</li>
		</ol>
	</div>
</template>

<script>
	import api from '.././api/index.js'
	export default {
		mounted() {
			// 做AJAX请求
			this._initData()
		},
		data() {
			return {
				list: ""
			}
		},
		methods: {
			_initData() {
				return new Promise((resolve, reject) => {
					var xhr = new XMLHttpRequest();
					xhr.open("GET", api.playlist + "?id=" + this.$route.params.id);
					xhr.send();
					xhr.addEventListener("readystatechange", function() {
						if(xhr.readyState == 4) {
							if(xhr.status == 200) {
								resolve(xhr.response);
							}
						}
					})
				}).then((res) => {
					this.list = JSON.parse(res).playlist.tracks
				})
			},
			handleClick(index){
				let id = this.list[index].id
				this.$router.push({
					path: `/song/${id}`
				})
			}
		}
	}
</script>

<style scoped>
	.u-smtitle {
		height: 23px;
		line-height: 23px;
		padding: 0 10px;
		font-size: 12px;
		color: #666;
		background-color: #eeeff0;
	}
	
	li,
	ul {
		margin: 0;
		padding: 0;
		-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
	}
	
	li {
		list-style: none;
	}
	
	.u-song {
		display: flex;
	}
	
	.u-song .sgi_fl {
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		-webkit-box-pack: center;
		-webkit-justify-content: center;
		justify-content: center;
		width: 40px;
		font-size: 17px;
		color: #999;
	}
	
	.u-song .sgi_fl,
	.u-song .sgi_fr {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
	}
	
	.f-bd {
		position: relative;
	}
	
	.u-song .sgi_fl,
	.u-song .sgi_fr {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
	}
	
	.u-song .sgi_fr {
		position: relative;
	}
	
	.u-song .sgi_fr,
	.u-song .sgich_fl {
		-webkit-box-flex: 1;
		-webkit-flex: 1 1 auto;
		flex: 1 1 auto;
	}
	
	.u-song .sgi_fr,
	.u-song .sgich_fl {
		-webkit-box-flex: 1;
		-webkit-flex: 1 1 auto;
		flex: 1 1 auto;
	}
	
	.u-song .sgich_fl {
		padding: 6px 0;
		width: 0;
	}
	
	.f-thide {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		word-break: normal;
	}
	
	.u-song .sgich_tl {
		font-size: 17px;
	}
	
	.u-song .sgich_info {
		font-size: 12px;
		color: #888;
	}
	
	.u-song .sgich_fr {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 0 10px;
	}
	
	.u-hmsprt {
		background: url(../../public/img/control.png) no-repeat;
		background-size: 166px 97px;
	}
	
	.u-song .sgich_ply {
		display: inline-block;
		width: 22px;
		height: 22px;
		background-position: -24px 0;
	}
	
	.f-bd:after {
		position: absolute;
		z-index: 2;
		content: "";
		top: 0;
		left: 0;
		pointer-events: none;
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		-webkit-transform-origin: top left;
		transform-origin: top left;
		border: 0 solid rgba(0, 0, 0, .1);
	}
	
	.f-bd-btm:after {
		border-bottom-width: 1px;
	}
</style>